@_default:
  just --list

# ------------------------------------------------------------------------------
# Recipes for the kornia-cpp project
# ------------------------------------------------------------------------------

# Build the C++ library only (no examples, no tests) - debug or release (default: debug)
build profile="debug":
  @echo "🏗️  Building kornia-cpp library ({{ profile }})..."
  cmake -B build -DCMAKE_BUILD_TYPE={{ if profile == "debug" { "Debug" } else { "Release" } }} -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF
  cmake --build build --target cargo_build -j$(nproc 2>/dev/null || sysctl -n hw.ncpu)

# Build tests only
build-tests profile="debug":
  @echo "🏗️  Building kornia-cpp tests ({{ profile }})..."
  cmake -B build -DCMAKE_BUILD_TYPE={{ if profile == "debug" { "Debug" } else { "Release" } }} -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=ON
  cmake --build build -j$(nproc 2>/dev/null || sysctl -n hw.ncpu)

# Build examples only
build-examples profile="debug":
  @echo "🏗️  Building kornia-cpp examples ({{ profile }})..."
  cmake -B build -DCMAKE_BUILD_TYPE={{ if profile == "debug" { "Debug" } else { "Release" } }} -DBUILD_EXAMPLES=ON -DBUILD_TESTS=OFF
  cmake --build build -j$(nproc 2>/dev/null || sysctl -n hw.ncpu)

# Run C++ tests
test profile="debug":
  @just build-tests {{ profile }}
  @echo "🧪 Running C++ tests..."
  cd build && ctest --output-on-failure

# Run tests with sanitizers enabled
test-sanitizers:
  @echo "🧪 Building and running tests with sanitizers..."
  cmake -B build -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON -DENABLE_SANITIZERS=ON
  cmake --build build -j$(nproc 2>/dev/null || sysctl -n hw.ncpu)
  cd build && ctest --output-on-failure

# Clean build artifacts
clean:
  @echo "🧹 Cleaning build artifacts..."
  rm -rf build/ target/

# Format C++ code (requires clang-format)
format:
  @echo "🎨 Formatting C++ code..."
  @if command -v clang-format >/dev/null 2>&1; then \
    find include src tests examples -type f \( -name "*.cpp" -o -name "*.hpp" \) -exec clang-format -i {} +; \
  else \
    echo "⚠️  clang-format not found. Install it with: sudo apt-get install clang-format"; \
    exit 1; \
  fi

# Check format without modifying (requires clang-format)
format-check:
  @echo "🔍 Checking C++ format..."
  @if command -v clang-format >/dev/null 2>&1; then \
    find include src tests examples -type f \( -name "*.cpp" -o -name "*.hpp" \) -exec clang-format --dry-run --Werror {} +; \
  else \
    echo "⚠️  clang-format not found. Install it with: sudo apt-get install clang-format"; \
    exit 1; \
  fi

# Install the library (requires sudo)
install: build
  @echo "📦 Installing kornia-cpp..."
  sudo cmake --install build

# Uninstall the library (requires sudo)
uninstall prefix="/usr/local":
  @echo "🗑️  Uninstalling kornia-cpp from {{ prefix }}..."
  sudo rm -rf {{ prefix }}/include/kornia
  sudo rm -f {{ prefix }}/lib/libkornia*.so
  sudo rm -f {{ prefix }}/lib/libkornia*.a
  sudo rm -rf {{ prefix }}/lib/cmake/kornia

